// Copyright (C) 2023 即时通讯网(52im.net) & Jack Jiang.
// The RainbowChat Project. All rights reserved.
// 
// 【本产品为著作权产品，合法授权后请放心使用，禁止外传！】
// 【本次授权给：<北京小羊驼科技有限公司>，授权编号：<NT231212144350>，代码指纹：<A.702363430.550>，技术对接人微信：<ID: wxid_wbyootvkdcgj22>】
// 【授权寄送：<收件：苏先生、地址：北京市大兴区北京密码西区6号楼1单元301、电话：18613885610、邮箱：bd@huiyuanxiang-inc.com>】
// 
// 【本系列产品在国家版权局的著作权登记信息如下】：
// 1）国家版权局登记名(简称)和权证号：RainbowChat    （证书号：软著登字第1220494号、登记号：2016SR041877）
// 2）国家版权局登记名(简称)和权证号：RainbowChat-Web（证书号：软著登字第3743440号、登记号：2019SR0322683）
// 3）国家版权局登记名(简称)和权证号：RainbowAV      （证书号：软著登字第2262004号、登记号：2017SR676720）
// 4）国家版权局登记名(简称)和权证号：MobileIMSDK-Web（证书号：软著登字第2262073号、登记号：2017SR676789）
// 5）国家版权局登记名(简称)和权证号：MobileIMSDK    （证书号：软著登字第1220581号、登记号：2016SR041964）
// * 著作权所有人：江顺/苏州网际时代信息科技有限公司
// 
// 【违法或违规使用投诉和举报方式】：
// 联系邮件：jack.jiang@52im.net
// 联系微信：hellojackjiang
// 联系QQ号：413980957
// 授权说明：http://www.52im.net/thread-1115-1-1.html
// 官方社区：http://www.52im.net
package com.x52im.rbchat.logic.chat_root.sendlocation.impl;

import android.app.Activity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;
import com.x52im.rbchat.R;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * 当前定位所对应的PIO兴趣点列表的wrapper包装类。
 *
 * <p>
 * 单独提炼出wapper类的目的，仅仅是为了减少它所依附的主类的代码量，
 * 从而提升主类代码的可读性和可维护性，这仅是一种设计模式和技巧，与功能无关。
 * </p>
 *
 * @author JackJiang
 * @since 6.0
 */
public abstract class GetLocationPOIListUIWrapper {
    private Activity parentActivity;

    private RecyclerView mRecyclerView;
    protected GetLocationPOIListAdapter mAddressListAdapter;
    private List<PoiItem> mList;

    private ImageView mProgressView;
    private Animation mProgressViewAnimation;

    private View mLayoutOfNoData;
    private TextView mHintViewOfNoData;

    public GetLocationPOIListUIWrapper(Activity parentActivity) {
        this.parentActivity = parentActivity;
        this.mList = new ArrayList<>();
        initGUI();
    }

    private void initGUI() {
        mRecyclerView = this.parentActivity.findViewById(R.id.chatting_get_location_activity_data_recyclerview);
        mProgressViewAnimation = AnimationUtils.loadAnimation(this.parentActivity, R.anim.widget_loading_big1);
        mProgressView = this.parentActivity.findViewById(R.id.chatting_get_location_activity_progress_view);
        mLayoutOfNoData = this.parentActivity.findViewById(R.id.chatting_get_location_activity_nodata_LL);
        mHintViewOfNoData = this.parentActivity.findViewById(R.id.chatting_get_location_activity_nodata_hintView);

        mAddressListAdapter = new GetLocationPOIListAdapter(this.parentActivity, mList){
            @Override
            protected void afterSetSelectPosition() {
                afterAdapterSetSelectPosition();
            }
        };
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this.parentActivity));
        mRecyclerView.setAdapter(mAddressListAdapter);
    }

    public List<PoiItem> getListDatas() {
        return this.mList;
    }

    public void notifyDataSetChanged() {
        this.mAddressListAdapter.notifyDataSetChangedAndResetSelection();
        this.mRecyclerView.smoothScrollToPosition(0);
    }

    protected abstract void afterAdapterSetSelectPosition();

    public GetLocationPOIListAdapter getAddressListAdapter() {
        return this.mAddressListAdapter;
    }

    public void showHintContent(String hint)
    {
        this.setNoDataHint(hint);
        this.showContent(GetLocationPOIListUIWrapper.ContentType.noData);
    }

    public GetLocationPOIListUIWrapper showContent(ContentType ct) {
        switch (ct) {
            case data: {
                this.mRecyclerView.setVisibility(View.VISIBLE);
                this.mProgressView.setVisibility(View.GONE);
                this.mProgressView.clearAnimation();
                this.mLayoutOfNoData.setVisibility(View.GONE);
                break;
            }
            case noData: {
                this.mRecyclerView.setVisibility(View.GONE);
                this.mProgressView.setVisibility(View.GONE);
                this.mProgressView.clearAnimation();
                this.mLayoutOfNoData.setVisibility(View.VISIBLE);

                this.mList.clear();
                this.mAddressListAdapter.setSelectPosition(-1);
                break;
            }
            case progress: {
                this.mRecyclerView.setVisibility(View.GONE);
                this.mProgressView.setVisibility(View.VISIBLE);
                this.mProgressView.startAnimation(mProgressViewAnimation);
                this.mLayoutOfNoData.setVisibility(View.GONE);

                this.mList.clear();
                this.mAddressListAdapter.setSelectPosition(-1);
                break;
            }
        }

        return this;
    }

    public GetLocationPOIListUIWrapper setNoDataHint(String hint) {
        this.mHintViewOfNoData.setText(hint);
        return this;
    }

    public enum ContentType{
        data,
        noData,
        progress
    }
}